package com.heima.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.behavior.ApUnLikesBehaviorControllerApi;
import com.heima.behavior.service.ApUnLikesBehaviorService;
import com.heima.model.behavior.dto.UnLikesBehaviorDto;
import com.heima.model.behavior.pojo.ApUnlikesBehavior;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/unLikeBehavior")
public class ApUnLikesBehaviorController implements ApUnLikesBehaviorControllerApi {

    @Autowired
    ApUnLikesBehaviorService apUnLikesBehaviorService;

    /**
     * 保存不喜欢行为
     * @param dto
     * @return
     */
    @PostMapping("/unLike")
    @Override
    public ResponseResult unlike(@RequestBody UnLikesBehaviorDto dto) {
        return apUnLikesBehaviorService.unlike(dto);
    }

    /**
     * 根据文章id和实体行为id查询
     * @param entryId
     * @param articleId
     * @return
     */
    @GetMapping("/getUnlike/{entryId}/{articleId}")
    @Override
    public ApUnlikesBehavior getUnlike(@PathVariable("entryId") Integer entryId,@PathVariable("articleId") Long articleId) {
        return apUnLikesBehaviorService.getOne(Wrappers.<ApUnlikesBehavior>lambdaQuery().eq(ApUnlikesBehavior::getArticleId,articleId).eq(ApUnlikesBehavior::getEntryId,entryId));
    }
}
